#!/usr/bin/perl -w
use strict;
use Getopt::Long;
#88888888888888888888888888888888888888888888888888888888888888888888888888888888

#   Usage

#88888888888888888888888888888888888888888888888888888888888888888888888888888888
my $usage = <<"USAGE";

USAGE:

    tab_delimited_to_fa.pl sequences.tab [--help]

        This script accepts sequences in a tab-delimited format
        i.e. accession<tab>sequence<newline>
        either via STDIN or on the command line and produces sequences
        reformatted in FASTA via STDOUT

USAGE

#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888


#	line_wrap

#			puts a newline every n letters
#			n.b. Do not use for constant parameters eg "$3"

#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

sub line_wrap($$)
{
	my @array;
	my $seq = $_[0];
	while (length $seq)
	{
		push @array, substr $seq, 0, $_[1], "";
	}
	return join "\n", @array;
}


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#   Get options

#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# mandatory


# optional parameters
my $help = undef;
GetOptions('help' => \$help);

die $usage if ($help);

my $line_cnt = 0;
my $seq_cnt = 0;

for (<>)
{
	++$line_cnt;
	chomp;
	next unless /([^\t]+)\t(.*)/;
	$seq_cnt++;
	print ">$1\n", line_wrap($2, 60), "\n";
}

print STDERR "\t$seq_cnt\tsequences parsed.\n";
